﻿using MediatR;
using ProductionLine.API.Application.Command.Car;
using ProductionLine.Domain.Car;
using ProductionLine.ErrorCode;
using ProductionLine.Infrastructure.Interface;

namespace ProductionLine.API.Application.Handler.Car
{
    public class GetCarHandler : IRequestHandler<GetCarCommand, APIResult<List<CarModel>>>
    {
        IBaseRepository<CarModel> carRepo;

        public GetCarHandler(IBaseRepository<CarModel> carRepo)
        {
            this.carRepo = carRepo;
        }

        public Task<APIResult<List<CarModel>>> Handle(GetCarCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<CarModel>> res = new APIResult<List<CarModel>>();
            var cars = carRepo.GetAll().Where(c => !c.IsDel).ToList();
            res.Msg = "查询车间信息成功";
            res.Data= cars.ToList();
            res.Code = APIEnum.Success;
            return Task.FromResult(res);
        }
    }
}
